package com.icinfo.cloud.provider.punish.simple.transfer.vo;

import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.icinfo.cloud.provider.common.enums.CertTypeEnum;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.vo.MemberDeptVo;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.vo.MemberOrgVo;
import com.icinfo.cloud.provider.punish.simple.transfer.model.CaseSimpleTransferRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.EnterTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import lombok.Data;
import java.util.Date;
import java.util.Map;
import java.util.Objects;

/**
 * 简单案件移交信息详情信息
 * @author HKxxx
 * @date 2024/2/1 16:59
 */
@Data
public class CaseSimpleTransferRecordVo {

    /*=====================标题======================*/
    /**
     * 标题-内容
     * 当事人名称（证件类型） 处罚事项
     */
    private String titleContent;

    /**
     * 标题-办案内容
     *  办案单位-办案部门|主办人
     */
    private String titleHandleContent;

    /*=====================当事人信息======================*/
    /**
     * 当事人
     */
    private String partyName;

    /**
     * 当事人类型(1个人，2法人)
     */
    private String partyType;

    /**
     * 个人/法人证件类型
     */
    private String certType;

    /**
     * 个人/法人证件号码
     */
    private String certCode;

    /**
     * 当事人/单位住址
     */
    private String address;

    /**
     * 联系电话
     */
    private String mobile;

    /**
     * 性别
     */
    private String sex;

    /**
     * 年龄
     */
    private String age;

    /**
     * 工作单位
     */
    private String workUnit;

    /**
     * 统一社会信用代码
     */
    private String uniscid;

    /**
     * 法人名称
     */
    private String legalName;

    /**
     * 单位类型(1:法人 2:个体工商户 3:其他组织)--当事人法人
     */
    private String entType;

    /**
     * 职务
     */
    private String job;

    /**
     * 经营地址
     */
    private String businessAddress;

    /*=====================关联处罚事项======================*/
    /**
     * 委托单位
     */
    private String entrustOrgName;
    /**
     * 事项名称
     */
    private String itemName;

    /**
     * 事项代码
     */
    private String itemCode;


    /*=====================办案单位信息======================*/
    /**
     * 办案单位
     */
    private String handleOrgName;

    /**
     * 办案部门
     */
    private String handleDeptName;

    /**
     * 主办人
     */
    private String mainHandlePerson;

    /**
     * 协办人
     */
    private String assistHandlePerson;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createTime;



    /*=====================交通信息======================*/
    /**
     * 是否无牌  （1-是 0-否）
     */
    private String hasLicensePlate;

    /**
     * 是否无证 （1-是 0-否）
     */
    private String hasDrivingLicence;

    /**
     * 移交备注
     */
    private String transferRemark;


    /*=====================取证======================*/
    /**
     * 案发地
     */
    private String happenAddress;

    /**
     * 案发时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date happenTime;

    /**
     * 反应内容
     */
    private String caseReactionContent;

    /**
     * 案件备注信息
     */
    private String caseRemark;

    /**
     * 取证照片
     */
    private JSONArray evidenceUrl;


    public static CaseSimpleTransferRecordVo convertRecordVo(CaseSimpleTransferRecord record,
                                                             Map<String, MemberOrgVo> orgVos,
                                                             Map<String, MemberDeptVo> deptVos){
        CaseSimpleTransferRecordVo vo = new CaseSimpleTransferRecordVo();
        String titleContent = "%s(%s)%s";
        String titleHandleContent = "办案人员：%s-%s|%s";
        // 办案部门名称
        MemberOrgVo handleOrg = orgVos.get(record.getHandleOrgCode());
        String handleOrgName = Objects.nonNull(handleOrg) ? handleOrg.getOrgName() : "";
        // 委托单位部门名称
        MemberDeptVo entrustDept = deptVos.get(record.getEntrustDeptCode());
        String entrustDeptName = Objects.nonNull(entrustDept) ? entrustDept.getDeptName() : "";
        // 办案单位部门名称
        MemberDeptVo handleDept = deptVos.get(record.getHandleDeptCode());
        String handleDeptName = Objects.nonNull(handleDept) ? handleDept.getDeptName() : "";
        // 个人证件名称
        String certTypeValue = CertTypeEnum.getValueByCode(record.getCertType());
        // 单位类型名称
        String entTypeValue = EnterTypeEnum.getValueByCode(record.getEntType());
        // 设置抬头
        vo.setTitleContent(
                String.format(titleContent,
                    record.getPartyName(),
                    PartyTypeEnum.PERSON.getCode().equals(record.getPartyType()) ? certTypeValue : entTypeValue,
                    record.getItemName())
        );
        vo.setTitleHandleContent(String.format(titleHandleContent, handleOrgName, handleDeptName, record.getMainHandlePerson()));
        vo.setPartyName(record.getPartyName());
        vo.setPartyType(record.getPartyType());
        vo.setCertType(certTypeValue);
        vo.setCertCode(record.getCertCode());
        vo.setAddress(record.getAddress());
        vo.setMobile(record.getMobile());
        vo.setSex(record.getSex());
        vo.setAge(record.getAge());
        vo.setWorkUnit(record.getWorkUnit());
        vo.setUniscid(record.getUniscid());
        vo.setLegalName(record.getLegalName());
        vo.setEntType(entTypeValue);
        vo.setJob(record.getJob());
        vo.setBusinessAddress(record.getBusinessAddress());
        vo.setEntrustOrgName(entrustDeptName);
        vo.setItemName(record.getItemName());
        vo.setItemCode(record.getItemCode());
        vo.setHandleOrgName(handleOrgName);
        vo.setHandleDeptName(handleDeptName);
        vo.setMainHandlePerson(record.getMainHandlePerson());
        vo.setAssistHandlePerson(record.getAssistHandlePerson());
        vo.setCreateTime(record.getCreateTime());
        vo.setHasLicensePlate(YesOrNoEnum.getValueByCode(record.getHasLicensePlate()));
        vo.setHasDrivingLicence(YesOrNoEnum.getValueByCode(record.getHasDrivingLicence()));
        vo.setTransferRemark(record.getTransferRemark());
        vo.setHappenAddress(record.getHappenAddress());
        vo.setHappenTime(record.getHappenTime());
        vo.setCaseReactionContent(record.getCaseReactionContent());
        vo.setCaseRemark(record.getCaseRemark());
        vo.setEvidenceUrl(JSONArray.parseArray(record.getEvidenceUrl()));
        return vo;
    }



}
